package com.open.source.rabbit.consumer.receiver;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;
import java.util.Arrays;

/**
 * created by zhanglong and since  2019/11/25  5:01 下午
 *
 * @description: 直连型消息消费监听器
 */
@Slf4j
@Component

public class DirectReceiver {

  //监听的队列名称 direct_queue
  @RabbitListener(queues = "direct_queue")
  public void onMessage(Message message, Channel channel) {
    log.info("直连型队列消息:" + new String(message.getBody(), Charset.defaultCharset()));
    //如果设置AcknowledgeMode是否为手动需要ack处理
//    channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);

  }
}


